package com.hl.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.domain.Article;
import com.hl.mapper.ArticleMapper;
import com.hl.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public Map<String, Object> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Article> articleList = articleMapper.findAll();
        PageInfo pageInfo = new PageInfo(articleList);
        Map<String, Object> map = new HashMap<>();
        //查询的数据
        map.put("articleList",pageInfo.getList());
        //数据总条目数
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public List<Article> findAllByTitle(String title) {
        return articleMapper.findAllByTitle(title);
    }

    @Override
    public int add(Article article) {
        return articleMapper.add(article);
    }

    @Override
    public int delById(int id) {
        return articleMapper.delById(id);
    }


    @Override
    public Article findById(int id) {
        return articleMapper.findById(id);
    }
    @Override
    public int updateById(Article article) {
        return articleMapper.updateById(article);
    }


}
